/*
 * Regola grammaticale
 * 
 * <termb> → <factb>[AND <factb>]*
 */
package composite.boolean_expression;

import composite.BooleanExpression;
import composite.Component;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import visitor.Visitor;

/**
 *
 * @author Antonio
 */
public class Termb extends BooleanExpression {
    
    private List<Component> factb;
    
    public Termb(Component factb) {
        
        this.factb = new LinkedList();
        this.factb.add(factb);
    }
    
    @Override
    public void add(Component factb) {
        
        this.factb.add(factb);
    }// add

    public List<Component> getState() {
        
        return factb;
    }// getState

    @Override
    public void interpreta(String contesto) {
        
        for (Component fb : factb) {
            
            fb.interpreta(contesto);
        }
    }
    
    @Override
    public void accept(Visitor v) {
        
        v.visit(this);
    }
    
    @Override
    public String toString() {
        
        StringBuilder sb = new StringBuilder();
        Iterator<Component> it = factb.iterator();
        
        sb.append(it.next());
        while (it.hasNext()) {
            
            sb.append(" && ").append(it.next());
            
        }
        return sb.toString();
    }
}
